﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WIC_Data_Manager
{
    public partial class fAddClinic : Form
    {
        string Year;
        public fAddClinic(string year)
        {
            InitializeComponent();
            Year = year;
            this.Text += (": " + this.Year);
        }

        private void bAdd_Click(object sender, EventArgs e)
        {
            if (Globals.IsNumeric(tbBreastfeeding.Text) && Globals.IsNumeric(tbPrenatal.Text) && Globals.IsNumeric(tbID.Text) && Globals.IsNumeric(tbNonBreastfeeding.Text) && Globals.IsMonth(tbMonth.Text))
            {
                string ID = tbID.Text;
                string Name = tbName.Text;
                string Prenatal = tbPrenatal.Text;
                string NonBreastfeeding = tbNonBreastfeeding.Text;
                string Breastfeeding = tbBreastfeeding.Text;
                int iTotal = Int32.Parse(tbBreastfeeding.Text) + Int32.Parse(tbNonBreastfeeding.Text);
                string Total = iTotal.ToString();
                int iPercentage = (int)((Double.Parse(tbBreastfeeding.Text) / (double)iTotal) * 100);
                string Percentage = iPercentage.ToString();
                string County = tbCounty.Text;
                string Month = tbMonth.Text;
                Month = Month.ToLower();
                Month = char.ToUpper(Month[0]) + Month.Substring(1);
                MessageBox.Show("Data approved. Will now send to server.", "Adding Clinic " + Name, MessageBoxButtons.OK, MessageBoxIcon.Information);
                Globals.DataBases.Participation.SimpleQuery("INSERT INTO y" + Year + "(ID,Name,Prenatal,NonBreastfeeding,Breastfeeding,Total,BFPercent,County,Month) VALUES (" + ID + ", '" + Name + "', " + Prenatal + ", " + NonBreastfeeding + ", " + Breastfeeding + ", " + Total + ", " + Percentage + ", '" + County + "', '" + Month + "')");
            }
            else
            {
                MessageBox.Show("One or more datafields are incorrect", "WIC Data Manager Data Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            
        }

        private void fAddClinic_FormClosed(object sender, FormClosedEventArgs e)
        {
            Globals.Forms.ManagerScreen.UpdateByYear(Year);
        }

        private void bIniAdd_Click(object sender, EventArgs e)
        {
            if (Globals.IsNumeric(tbIniPercentage.Text) && Globals.IsMonth(tbIniMonth.Text) && Globals.IsNumeric(tbIniID.Text))
            {
                string ID = tbIniID.Text;
                string Name = tbIniName.Text;
                string Percentage = tbIniPercentage.Text;
                string County = tbIniCounty.Text;
                string Month = tbIniMonth.Text;
                Month = Month.ToLower();
                Month = char.ToUpper(Month[0]) + Month.Substring(1);
                MessageBox.Show("Data approved. Will now send to server.", "Adding Clinic " + Name, MessageBoxButtons.OK, MessageBoxIcon.Information);
                Globals.DataBases.Initiation.SimpleQuery("INSERT INTO y" + Year + "(ID,Name,Percent,County,Month) VALUES (" + ID + ", '" + Name + "', " + Percentage + ", '" + County + "', '" + Month + "')");
            }
            else
            {
                MessageBox.Show("One or more datafields are incorrect", "WIC Data Manager Data Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }
    }
}
